package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.User;
import com.example.demo.pojo.request.BaseRequest;
import com.example.demo.pojo.request.UserPageRequest;
import com.example.demo.service.IuserService;
import jakarta.persistence.criteria.CriteriaBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/user")
public class userControl {
    @Autowired
    private IuserService userService;
    //查询全部
    @GetMapping("/list")
    public Result list(){
        List<User> select = userService.list();
        return Result.success(select);
    }

    //分页查询
    @GetMapping("/page")
    public Result page(UserPageRequest userPageRequest){
        Object page = userService.page(userPageRequest);
        return Result.success(page);
    }

    //添加数据
    @PostMapping("/add")
    public Result add(@RequestBody User user){
        userService.save(user);
        return Result.success();
    }

    //根据id编辑回写
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        User user = userService.getUser(id);
        return Result.success(user);
    }

    //根据id编辑
    @PutMapping("/update")
    public Result update(@RequestBody User user){
        userService.getIDUser(user);
        return Result.success();
    }

    //根据id删除
    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable Integer id){
        userService.delete(id);
        return Result.success();
    }






}
